package com.tledu.controller;

import com.tledu.domain.User;
import com.tledu.service.IUserService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author cyrus
 */
@Controller
@RequestMapping("/hello")
//@AllArgsConstructor
public class HelloController {
//    private IUserService userService;

    @RequestMapping("/index")
    @ResponseBody
    public String hello() {
//        userService.print();
        return "hello!";
    }

    @RequestMapping("/test/name")
    @ResponseBody
    public String test(String name) {
        return "test name" + name;
    }


    @RequestMapping("/delete/{id}")
    @ResponseBody
    public String pathParams(@PathVariable("id") String ids) {
        System.out.println("Path参数:"+ids);
        return "success";
    }

    @RequestMapping("/date")
    @ResponseBody
    public String date(User user, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date today) {
        System.out.println(today);
        System.out.println(user);
        return "success";
    }

    @RequestMapping("/dateJson")
    @ResponseBody
    public String dateJson(@RequestBody  User user) {
        System.out.println(user);
        return "success";
    }

    @RequestMapping("/hello")
    public String hello2() {
        return "Hello";
    }

    @RequestMapping("/json")
    @ResponseBody
    public User jsonObject(User user) {
        return user;
    }

    @RequestMapping("/jsonArr")
    @ResponseBody
    public List<User> jsonArr() {
        List<User> users = new ArrayList<User>();
        users.add(new User("张三",19,null,null,null,null));
        users.add(new User("李四",20,null,null,null,null));
        return users;
    }
}
